<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
	String purchase_id = request.getParameter("purchase_id")==null?"":request.getParameter("purchase_id");
%>
<html>
	<head>
		<title>已完成入库单</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listPageFinishPurchaseProductIn?purchase_id=<%=purchase_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'订单id',field:'purchase_id',hidden:true}
				]],
				columns:[[
					{title:'订单编号',field:'code',width:150,align:'center'},
					{title:'入库单号',field:'in_code',width:150,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					{title:'日期',field:'operation_date',width:100,align:'center'},
					{title:'供货商',field:'supplier',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'状态',field:'status',hidden:true},
					{title:'状态',field:'status_desc',width:100,align:'center'},
					{title:'审批查看',field:'shenpichakan',width:50,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status != '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_PRODUCT_IN_SHENPI%>")+"','"+rowData.id+"');\"/>";
						}
						return "";
			        }},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEdit(1,'"+rowData.id+"','"+rowData.purchase_id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteBusiness('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.purchase_id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEdit(1,'"+rowData.id+"','"+rowData.purchase_id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.purchase_id+"');\"/>";
						}
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEdit(2,'"+rowData.id+"','"+rowData.purchase_id+"');\"/>";
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var product_in_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/warehouse/listPurchaseProductInDetail?product_in_id='+product_in_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'产品编号',field:'code',width:150,align:'center'},
							{title:'产品名称',field:'name',width:300,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'申请数量',field:'num',width:100,align:'center'},
							{title:'已入库',field:'receive_num',width:100,align:'center'},
							{title:'本次入库',field:'inNum',width:100,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:'#tb',
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function shenpi(obj,id,purchase_id){
		      var flowBusinessUrl='<%=contextPath %>/springViews/warehouse/addOrEditPurchaseProductIn.jsp?isShow=1&purchase_id='+purchase_id+'&product_in_id='+id;
		      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_PRODUCT_IN_SHENPI%>")+"&businessId="+id;
		      $(obj).hide();
		      $.ajax({
							type:'POST',
							url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
							dataType:"JSON",
							data:param,
							success:function(rtJson){
								if (rtJson.rtState == '0'){
									openDialogResize(rtJson.rtData.url,1000,800);
								}else{
									warningInfo(rtJson.rtMsrg);
								}
								$(obj).show();
							}
						});
		}
		function addOrEdit(type,id,purchase_id){
			if(type==1){
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditPurchaseProductIn.jsp?callback=rtCallBack&purchase_id='+purchase_id+'&product_in_id='+id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditPurchaseProductIn.jsp?callback=rtCallBack&isShow=1&purchase_id='+purchase_id+'&product_in_id='+id,1000, 800);	
			}
		}
		
		function deleteBusiness(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deletePurchaseProductIn",
						data:"product_in_id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function doSearch()
		{	
			var firstDay = $('#start_date').datebox('getValue');
			var endDay = $('#end_date').datebox('getValue');
			var searchValue = $('#searchValue').val();
			var dept_id = $('#dept_id').combotree('getValue');
			$('#table').datagrid('load',{
				start_date:firstDay,
				end_date:endDay,
				dept_id:dept_id,
				searchValue:searchValue
				});
		}
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				开始日期: <input id="start_date" name="start_date" style="width:120px" class="easyui-datebox"/>
				结束日期: <input id="end_date" name="end_date" style="width:120px" class="easyui-datebox"/>
				选择部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">
				工单编号/名称/入库单号：<input id="searchValue" name="searchValue" style="width:160px" title="工单编号/名称/入库单号"  placeholder="工单编号/名称 /入库单号"/>&nbsp;&nbsp;  			
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
